﻿using System;
namespace Producers.Calcdoc.Xtee.Riik.Ee.Producer.Calcdoc.Messages {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="SubtractResponse", Namespace="http://producers.calcdoc.xtee.riik.ee/producer/calcdoc", Target=typeof(SubtractResponse))]
    public class SubtractResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISubtractResponse clazz;
        
        public SubtractResponseSerializer(ISubtractResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("request");
            if (clazz.Request!=null) {
                global::Xtee.Core.SerializationMetadata metaRequest = this.GetMetaData(clazz.Request);
                metaRequest.NewSerializer(clazz.Request).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Request");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("response");
            if (clazz.Response!=null) {
                global::Xtee.Core.SerializationMetadata metaResponse = this.GetMetaData(clazz.Response);
                metaResponse.NewSerializer(clazz.Response).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Response");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="request") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>SubtractResponse>request");
                }
                global::Xtee.Core.SerializationMetadata metaRequest = this.GetMetaData<global::Producers.Calcdoc.Xtee.Riik.Ee.Producer.Calcdoc.IVariables>(Reader, "Variables", "http://producers.calcdoc.xtee.riik.ee/producer/calcdoc");
                clazz.Request = metaRequest.NewEntity<global::Producers.Calcdoc.Xtee.Riik.Ee.Producer.Calcdoc.IVariables>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("request");
                    metaRequest.NewSerializer(clazz.Request).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>SubtractResponse>request", Reader.LocalName);
            }
            if (Reader.LocalName=="response") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>SubtractResponse>response");
                }
                global::Xtee.Core.SerializationMetadata metaResponse = this.GetMetaData<global::Producers.Calcdoc.Xtee.Riik.Ee.Producer.Calcdoc.IResult>(Reader, "Result", "http://producers.calcdoc.xtee.riik.ee/producer/calcdoc");
                clazz.Response = metaResponse.NewEntity<global::Producers.Calcdoc.Xtee.Riik.Ee.Producer.Calcdoc.IResult>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("response");
                    metaResponse.NewSerializer(clazz.Response).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>SubtractResponse>response", Reader.LocalName);
            }
        }
    }
}
